package algorithm;

public class leetcode_0474 {
    public static void main(String[] args) {
        String[] num={"10","0","1"};
        findMaxForm(num,1,1);
    }
    public static int findMaxForm(String[] strs, int m, int n) {
        int len=strs.length;
        int [][][] dp=new int[len+1][m+1][n+1];
        for(int i=1;i<=len;++i){
            for(int j=0;j<=m;++j){
                for(int k=0;k<=n;++k){
                    int [] num=num(strs[i-1]);
                    if(num[0]<=j&&num[1]<=k){
                        dp[i][j][k]=dp[i-1][j-num[0]][k-num[1]]+1;
                    }
                    dp[i][j][k]=Math.max(dp[i][j][k],dp[i-1][j][k]);
                }
            }
        }
        return dp[len][m][n];
    }
    public static int[] num(String s){
        int len=s.length();
        int[] result=new int[2];
        for(int i=0;i<len;++i){
            if(s.charAt(i)=='0') result[0]+=1;
            else result[1]+=1;
        }
        return result;
    }
}
